package com.wx.service.impl;

import com.wx.dao.DrugDao;
import com.wx.dao.InDao;
import com.wx.dao.impl.DrugDaoImpl;
import com.wx.dao.impl.InDaoImpl;
import com.wx.domain.Drug;
import com.wx.service.DrugService;

import java.util.List;

public class DrugServiceImpl implements DrugService {
    private DrugDao drugDao=new DrugDaoImpl();
    private InDao inDao=new InDaoImpl();
    @Override
    public List<Drug> getAllDrug(String pageIndex, String pageSize) {
        return drugDao.getAllDrug(pageIndex,pageSize);
    }

    @Override
    public List<Drug> getDrugByName(String drugName) {
        return drugDao.getDrugByName(drugName);
    }

    @Override
    public void addDrugNumber(String drugId, int inNumber) {
        drugDao.addDrugNumber(drugId,inNumber);
    }

    @Override
    public boolean addDrug(Drug drug, String doctorId) {
        Drug drug1 = drugDao.getDrugByDrugName(drug.getDrugName());
        String inDate = System.currentTimeMillis()+"";
        if (drug1!=null){
            drugDao.addDrugNumber(String.valueOf(drug1.getDrugId()),drug.getDrugNumber());
            inDao.addDrugNumber(String.valueOf(drug1.getDrugId()),doctorId,drug.getDrugNumber(),inDate);
            return true;
        }else {
            drugDao.addDrug(drug);
            return true;
        }
    }
}
